package com.yanyeori.seata.service.impl;

import com.yanyeori.framework.core.model.WebResponse;
import com.yanyeori.seata.client.ServiceBClient;
import com.yanyeori.seata.dao.BankMapper;
import com.yanyeori.seata.entity.Bank;
import com.yanyeori.seata.service.TestService;
import io.seata.spring.annotation.GlobalTransactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chenkuan
 * @since 2022/3/29 029 10:48
 */
@Service
public class TestServiceImpl implements TestService {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ServiceBClient serviceBClient;
    @Autowired
    private BankMapper bankMapper;

    @GlobalTransactional
    @Override
    public WebResponse test() {
        //操作数据库bank
        Bank bank = new Bank();
        bank.setId(1L);
        bank.setUpdateUser("seata-a");
        bankMapper.updateById(bank);
        //调用远程服务seata-b-business
        WebResponse response = serviceBClient.rest("seata a调用b参数");
        logger.info("远程服务返回：{}", response);
        int i = 1 / 0;
        return response;
    }
}
